package com.cloud.utils.base;




/**
 * @author：mengxiangzhong
 * @date：2023/1/30 14:19
 * @todo： 视图统一返回
 */

public class DataResult<T> {

    private Integer code;

    private String message;
    private boolean success;

    private T data;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public DataResult(Integer code, String message, boolean success, T data) {
        super();
        this.code = code;
        this.message = message;
        this.success = success;
        this.data = data;
    }



    public DataResult() {
        super();
        // TODO Auto-generated constructor stub
    }

    public static DataResult buildSuccess() {
        return new DataResult(200, "返回正确", true, null);
    }

    public static DataResult buildSuccess(Object t) {
        return new DataResult(200, "返回正确", true, t);
    }

    public static <T> DataResult buildSuccess(String msg, T t) {
        return new DataResult(200, msg, true, t);
    }

    public static DataResult buildSuccess(Integer code, String msg, Object t) {
        return new DataResult(code, msg, true, t);
    }

    public static DataResult buildFail() {
        return new DataResult(201, "返回失败", false, null);
    }

    public static DataResult buildFail(String msg) {
        return new DataResult(201, msg, false, null);
    }

    public static DataResult buildFail(Integer code, String msg) {
        return new DataResult(code, msg, false, null);
    }

    public static DataResult buildFail(String msg, Object data) {
        return new DataResult(201, msg, false, data);
    }

    public static DataResult buildFail(Integer code, String msg, Object obj) {
        return new DataResult(code, msg, false, obj);
    }

    public static DataResult  buildByInter(Integer  curdRes) {
        if(curdRes > 0) {
            return buildSuccess();
        }
        return buildFail();
    }


    public static DataResult  buildByStr(String  res) {
        if(res == null) {
            return buildSuccess();
        }
        return buildFail(res);
    }

}
